const countFiled =  (list, name) => {
  const obj = list.reduce((prev, cur) => {
    const val = cur.get(name)
    prev[val] = prev[val] ? prev[val] + 1 : 1
    return prev
  }, {})
  return Object.keys(obj).filter(field => obj[field] > 1).map(field => ({
    field,
    count: obj[field]
  }))
}
Parse.Cloud.define('countField', async (req, res) => {
  try {
    const findIpList = new Parse.Query('RoTask').exists('ip').limit(1000000).select(['ip']).find()
    const findImeiList = new Parse.Query('RoTask').exists('imei').limit(100000).select(['imei']).find()
    const ipList = await findIpList
    const imeiList = await findImeiList
    res.success({
      ip: countFiled(ipList, 'ip'),
      imei: countFiled(imeiList, 'imei')
    })
  } catch (err) {
    res.error(err)
  }
})
